package lc.双指针;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/24
 */
public class 剑指Offer21_调整数组顺序使奇数位于偶数前面 {

    public int[] exchange(int[] nums) {

        int l = 0;
        int r = nums.length-1;
        while (l < r) {
            while (nums[l] % 2 != 0 && l < r) {
                l++;
            }
            while (nums[r] % 2 == 0 && l < r) {
                r--;
            }
            if (l  < r) {
                int temp = nums[l];
                nums[l] = nums[r];
                nums[r] = temp;
            }

        }
        return nums;
    }
}
